﻿@{
    ViewBag.Title = "第三方巡检计划";
    Layout = "~/Views/Shared/PlanPartial/_LayoutDetail.cshtml";
}

@using Wicresoft.UnifyShow2.Portal.Extensions;
@using Wicresoft.UnifyShow.Business;

@{
    var thirdTypes = ViewData["ThirdInspectionType"] as List<InspectionType>;
    var range = ViewData["InspectionRange"] as List<PlanLocationOwner>;
    var currentUser = ViewBag.CurrentUser as User_XModel;

    var Model = ViewData["Model"] as ScheduleJob;
    var isView = Model != null && Model.Job != null;
    var job = isView ? Model.Job : null;
    var jobRange = (isView && job != null && job.JobRange != null) ? job.JobRange.Split(';').ToList() : null;

    //创建人可以编辑计划
    var canEdit = (isView && currentUser.ID == job.JobOwnerID) || !isView;
    //是否省局人员
    var isGlobal = (bool)ViewData["IsGlobal"];
}

@section Name{第三方巡检计划名称：}
@section Description{第三方巡检计划描述：}
@section CycleTitle{第三方巡检计划时间以及周期设置：}

@section ThirdInspectionType{
    <div class="parameter">
        <div class="parameter_name">
            <span class="required">*</span>
            第三方巡检类型：
        </div>
        <div class="parameter_input short">
            <select id="InspRange" style="width: 104px;" data-required-info="请选择第三方巡检类型!" data-model-source="ThirdTypeID">
                @foreach (var item in thirdTypes)
                {
                    <option value="@item.ID" @((isView && job != null && job.ThirdTypeID == item.ID) ? " selected='selected'" : "")>@item.Name</option>
                }
            </select>
        </div>
    </div>
}

@section Responsible{
    <div class="parameter">
        <div class="parameter_name">
            <span class="required">*</span>
            责任人：
        </div>
        <div class="parameter_input short">
            <input type="text" disabled="disabled" value="@(isView ? job.TaskUserName : "")" data-required-info="请选择责任人!" data-from="username" id="Responsible" />
            <input type="hidden" id="ResponsibleID" value="@(isView ? job.TaskUserID.ToString() : "")" data-model-source="TaskUserID" data-from="userid" />
            @if (canEdit)
            {
                <span class="icon-search" onclick="openResponsibleSearch();"></span>
            }
        </div>
    </div>
}

@section InspectionRange
{
    @if (isGlobal)
    {
        <div class="parameter_name">第三方巡检范围：</div>
        <div id="taskRangeContainer">
            <input type="checkbox" id="checkAllRange" class="list_all" data-required-info="请选择第三方巡检范围!" name="range" />
            <label for="checkAllRange">全选</label>
            @foreach (var item in range)
            {
                <input type="checkbox" id="range_@(item.LocationID)" name="range" @((isView && jobRange != null && jobRange.Contains(item.LocationID.ToString())) ? "checked='checked'" : "") class="list_item" value="@(item.LocationID)" />
                <label for="range_@(item.LocationID)">@item.Alias</label>
            }
        </div>
    }
    else
    {
        //地市的第三方巡检看不见巡检范围
        var location = range.FirstOrDefault();
        <div id="taskRangeContainer" style="display: none;">
            <input type="checkbox" id="range_@(location.LocationID)" name="range" checked="checked" class="list_item" value="@(location.LocationID)" />
            <label for="range_@(location.LocationID)">@location.Alias</label>
        </div>
    }
}

<script type="text/javascript">
    var SavePlan = function () {

        var data = {};

        data["JobType"] = 2;

        data["ThirdTypeName"] = $('#InspRange').find('option:selected').text();

        var range = "";
        $('[name="range"]:checked:not("#checkAllRange")').each(function () {
            range += $(this).val() + ";";
        });
        data["JobRange"] = range;

        planSave(data);
    };

    $(function () {
        var canEdit = $('#canEdit').val() == "True";
        if (canEdit) {
            window.setTimeout(function () {
                enableControl('taskRangeContainer');
            }, 0);
        }
    });
</script>
